package com.jyy.prefabricated.service;

import com.jyy.prefabricated.entity.StudentQuestionCollection;
import com.jyy.prefabricated.exception.CustomException;
import com.jyy.prefabricated.mapper.StudentQuestionCollectionMapper;
import com.jyy.prefabricated.mapper.StudentQuestionCollectionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @version 1.0.0
 * @author: zjj
 */

@Service
public class StudentQuestionCollectionService {

    @Autowired
    private StudentQuestionCollectionMapper studentQuestionCollectionMapper;

    /**
     * 新增
     * @param studentQuestionCollection
     * @return
     */
    public Integer insert(StudentQuestionCollection studentQuestionCollection){
        studentQuestionCollectionMapper.insert(studentQuestionCollection);
        return studentQuestionCollection.getId();
    }

    /**
     * 更新
     * @param studentQuestionCollection
     * @return
     */
    public int update(StudentQuestionCollection studentQuestionCollection){
        if(studentQuestionCollection.getId() == null){
            throw new CustomException("参数id不能为空");
        }
        return studentQuestionCollectionMapper.updateByPrimaryKeySelective(studentQuestionCollection);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    public int delete(Integer id){
        return studentQuestionCollectionMapper.deleteByPrimaryKey(id);
    }

    /**
     * 删除题库收藏
     * @param questionBankId
     * @param studentId
     * @return
     */
    public int deleteByQuestionBankIdAndStudentId(Integer questionBankId, Integer studentId){
        return studentQuestionCollectionMapper.deleteByQuestionBankIdAndStudentId(questionBankId, studentId);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    public StudentQuestionCollection selectById(Integer id){
        return studentQuestionCollectionMapper.selectByPrimaryKey(id);
    }
}
